#include <bits/stdc++.h>
using namespace std;
const int maxn = 20+2;
bool m[maxn][maxn];
bool vis[maxn];
int D;
int cnt;

int p[maxn];
int find(int x){
    return  x == p[x]? x : x = find(p[x]);
}

void print(vector<int> &v){
    for(int i=0; i<v.size(); ++i) {
        if(i) cout << " ";
        cout << v[i];
    }
    cout << "\n";
    ++cnt;
}

void dfs(vector<int> &v){
    if(v.back() == D) print(v);
    else{
        int p = v.back();
        for (int i = 1; i <= 20; ++i) {
            if(m[p][i] && !vis[i]){
                v.push_back(i);
                vis[i] = true;
                dfs(v);
                v.pop_back();
                vis[i] = false;
            }
        }
    }
}

void init(){
    cnt = 0;
    memset(m, false, sizeof(m));
    memset(vis, false, sizeof(vis));
    iota(p, p+maxn, 0);
}

int main() {
    ios_base::sync_with_stdio(false);cin.tie(nullptr);
    int kase = 0;
    while(cin >> D){
        cout << "CASE " << ++kase << ":\n";
        init();
        int a, b;
        while(cin >> a >> b && a && b){
            m[a][b] = m[b][a] = true;
            int pa = find(a), pb = find(b);
            p[pa] = pb;
        }
        int ps = find(1), pe = find(D);
        if(ps==pe) {
            vector<int> v(1, 1);
            vis[1] = true;
            dfs(v);
        }
        cout << "There are " << cnt << " routes from the firestation to streetcorner " << D << ".\n";
    }
    return 0;
}